package com.hfzy.ihk.common.core.elasticsearch.entity;


import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hfzy.ihk.common.facade.BaseEntity;
import com.hfzy.ihk.common.facade.elasticsearch.ElasticsearchTableOperation;
import com.hfzy.ihk.common.facade.elasticsearch.entity.ElasticsearchTable;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;

/**
 * <p>
 * <p>
 * </p>
 * 事务操作失败信息存储，30分钟重试
 *
 * @author wws
 * @since 2018-01-13
 */

@Document(indexName = "#{elasticSearchConfig.indexName()}_opt_error_msg", shards = 24, replicas = 2, type = "data")
public class OperationErrorMsg implements BaseEntity {

    private static final long serialVersionUID = 1L;

    @Id
    private String id;

    private Long version = 1L;

    /**事务id: key*/
    @Field(type = FieldType.Keyword)
    private String txId;

    @Field(type = FieldType.Keyword)
    private String topic;

    @Field(type = FieldType.Keyword)
    private String partition;

    @Field(type = FieldType.Keyword)
    private String optTable;

    @Field(type = FieldType.Keyword)
    private String optMethod;

    /** data Json Array str*/
    @Field(type = FieldType.Keyword)
    private String jsonArrayMessage;

    /**是否已处理*/
    private boolean hasDeal;

    private String exceptionMsg;

    /**重试次数*/
    private int retryTimes = 0;

    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    /**fastjson局部更新起作用:
	* 比如增加一条意向
	* */
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Override
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    public String getJsonArrayMessage() {
        return jsonArrayMessage;
    }

    public void setJsonArrayMessage(String jsonArrayMessage) {
        this.jsonArrayMessage = jsonArrayMessage;
    }

    public boolean isHasDeal() {
        return hasDeal;
    }

    public void setHasDeal(boolean hasDeal) {
        this.hasDeal = hasDeal;
    }

    public String getTxId() {
        return txId;
    }

    public void setTxId(String txId) {
        this.txId = txId;
    }

    public String getTopic() {
        return topic;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getPartition() {
        return partition;
    }

    public void setPartition(String partition) {
        this.partition = partition;
    }

    public String getOptTable() {
        return optTable;
    }

    public void setOptTable(String optTable) {
        this.optTable = optTable;
    }

    public String getOptMethod() {
        return optMethod;
    }

    public void setOptMethod(String optMethod) {
        this.optMethod = optMethod;
    }

    public String getExceptionMsg() {
        return exceptionMsg;
    }

    public void setExceptionMsg(String exceptionMsg) {
        this.exceptionMsg = exceptionMsg;
    }

    public int getRetryTimes() {
        return retryTimes;
    }

    public void setRetryTimes(int retryTimes) {
        this.retryTimes = retryTimes;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public String toString() {
        return "CrmTransactionalErrorMsg{" +
                ", id=" + id +
                ", version=" + version +
                ", msg=" + jsonArrayMessage +
                ", hasDeal=" + hasDeal +
                "}";
    }
}
